package com.onlinemovies.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.onlinemovies.entity.MovieDetails;
import com.onlinemovies.entity.ShowDetails;
import com.onlinemovies.service.MovieService;
import com.onlinemovies.service.ShowService;


@Controller
@RequestMapping(value = { "/show" })
public class ShowController {
	@Autowired
	private ShowService showService;
	@Autowired
	private MovieService movieService;
	
	@RequestMapping(value = { "", "/" })
	public ModelAndView halldetails() throws Exception {

		Map<String, Object> params = new HashMap<String, Object>();

		List<ShowDetails> shows = showService.getAll();

		params.put("shows", shows);

		params.put("show", new ShowDetails());
		
		List<MovieDetails> all = movieService.getAll();
		params.put("movieList", all);
		return new ModelAndView("show", params);
	}
	
	@RequestMapping("/insert")
	public ModelAndView insert(@ModelAttribute("show") ShowDetails show)
			throws Exception {

		Map<String, Object> params = new HashMap<String, Object>();

		

		showService.doInsert(show);
		//return new ModelAndView("hall",null);
		return new ModelAndView("redirect:/show");
		
	}


	@RequestMapping("/about")
	public ModelAndView about() throws Exception {
		return new ModelAndView("about", null);
	}
	

}
